<?php
use yii\db\Query;
use common\components\helpers\Fun;
$id=\Yii::$app->request->get('id');
if (isset($id)){
    $customer_relationship=(new Query())->select('*')->from('{{%customer_relationship}}')->where(['id'=>$id])->one(Fun::getSiteDb());
    if (isset($customer_relationship)){
        $vice_responsibility_man = (new Query())->select('name')->from('{{%admin}}')
            ->where(['in', 'id', explode(',', $customer_relationship['admin_child_ids'])])->column(Fun::getSiteDb());
        $admin_child_ids = implode('/', $vice_responsibility_man);
    }
}
$action_id=\Yii::$app->controller->action->id;
if($action_id=='create'){
    return [
        'id' => 'customerrelationship-form',
        'template' => 'form_default',
        'enableClientValidation' => false,
        'enableAjaxValidation' => true,
        'options' => ['class' => 'form-validate'],
        'models' => [
            'customerrelationship' => [
                'title' => '添加客户',
                'th_with' => 80,
                'elements' => [
                    'name' => [
                        'type' => 'text',
                        'options' => ['class' => 'input-text']
                    ],
                    'sex' => [
                        'type' => 'radiolist',
                        'items' => [
                            '0' => '男',
                            '1' => '女',
                        ],
                    ],

                    'mobile' => [
                        'type' => 'text',
                        'options' => ['class' => 'input-text']
                    ],
                    'category_id' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择意向类别'
                        ]
                    ],

                    'admin_id' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择市场负责人'
                        ]
                    ],
                    'admin_child_ids' => [
                        'type'=>'widget',
                        'class'=> \kartik\select2\Select2::className(),
                        'data' => yii\helpers\ArrayHelper::map(\zhtfrontend\models\datas\Admin::find()->where(['status'=>1])->andWhere(['in' ,'role',['marketing_commissioner']])->all(),'id','name'),
                        'options' => ['class' => 'input-text','multiple' => true,'placeholder' => empty($admin_child_ids)?'请选择市场副负责人':$admin_child_ids]
                    ],
                    /*'salesman_id' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择跟进负责人'
                        ]
                    ],*/
                    'source' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户来源'
                        ]
                    ],
                    'channel' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择获客渠道'
                        ]
                    ],
                    'status' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户类型'
                        ]
                    ],
                    'maturity' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户成熟度'
                        ]
                    ],
                    'remark'=>[
                        'type'=>'textarea',
                        'options'=>[
                            'class'=>'input-textarea',
                            'prompt' => '备注'
                        ]
                    ],
                ],
            ]
        ]
    ];
}else{
    return [
        'id' => 'customerrelationship-form',
        'template' => 'form_default',
        'enableClientValidation' => false,
        'enableAjaxValidation' => true,
        'options' => ['class' => 'form-validate'],
        'models' => [
            'customerrelationship' => [
                'title' => '添加客户',
                'th_with' => 80,
                'elements' => [
                    'name' => [
                        'type' => 'text',
                        'options' => ['class' => 'input-text']
                    ],
                    'sex' => [
                        'type' => 'radiolist',
                        'items' => [
                            '0' => '男',
                            '1' => '女',
                        ],
                    ],

                    'mobile' => [
                        'type' => 'text',
                        'options' => ['class' => 'input-text']
                    ],
                    'category_id' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择意向类别'
                        ]
                    ],

                    /* 'admin_id' => [
                         'type' => 'dropdownlist',
                         'option'=>[
                             'encode'=>false,
                             'style'=>'width:220px',
                             'prompt' => '请选择负责人'
                         ]
                     ],
                     'admin_child_ids' => [
                         'type'=>'widget',
                         'class'=> \kartik\select2\Select2::className(),
                         'data' => yii\helpers\ArrayHelper::map(\zhtfrontend\models\datas\Admin::find()->where(['status'=>1])->andWhere(['in' ,'role',['marketing_director','marketing_commissioner']])->all(),'id','name'),
                         'options' => ['multiple' => true,'placeholder' => empty($admin_child_ids)?'请选择副负责人':$admin_child_ids]
                     ],
                     'salesman_id' => [
                         'type' => 'dropdownlist',
                         'option'=>[
                             'encode'=>false,
                             'style'=>'width:220px',
                             'prompt' => '请选择跟进负责人'
                         ]
                     ],*/
                    'source' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户来源'
                        ]
                    ],
                    'channel' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择获客渠道'
                        ]
                    ],
                    'status' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户类型'
                        ]
                    ],
                    'maturity' => [
                        'type' => 'dropdownlist',
                        'option'=>[
                            'encode'=>false,
                            'style'=>'width:220px',
                            'prompt' => '请选择客户成熟度'
                        ]
                    ],
                    'remark'=>[
                        'type'=>'textarea',
                        'options'=>[
                            'class'=>'input-textarea',
                            'prompt' => '备注'
                        ]
                    ],
                ],
            ]
        ]
    ];
}

